// pages/user/index/coloruiIndex.js
const app = getApp()
const http = require('../../../utils/http.js')
Component({
  /**
   * 组件的属性列表
   */
  properties: {

  },
  options: {
    addGlobalClass: true,
  },
  lifetimes: {
    attached: function() {
      // 在组件实例进入页面节点树时执行
      if (!app.globalData.userInfo.mobile) {//授权了，可以获取用户信息了
        //重定向到指定的页面
        wx.navigateTo({
            url: "/pages/auth/auth"
        });
      }else{
        this.setData({
          customer: app.globalData.customer,
          userInfo: app.globalData.userInfo,
        })
        this.getMember()
      }
    }
  },
  pageLifetimes: {
    show: function() {
      // 页面被展示
      this.setData({
        userInfo: app.globalData.userInfo,
      })
      this.getMember()
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    amount: 0,
    integral: 0,
    couponSize: 0,
    userInfo: null,
    customer: null,
    member: {}
  },

  /**
   * 组件的方法列表
   */
  methods: {
    //视频号测试
    spBtn:function(){
      wx.navigateTo({
        url: 'plugin-private://wx34345ae5855f892d/pages/productDetail/productDetail?productId=40323675',
      })
    },
// 积分兑换按钮
    btnClick:function(e){
        //console.log('123')
        wx.showLoading({
          title: '加载中',
          mask: true
        })
        let that = this;
          var item = e.currentTarget.dataset;
          let date = new Date()
          let date1 = new Date(that.data.activity.beginTime.replace(/-/g, '/'))
          //console.log(date1)
          let date2 = new Date(that.data.activity.endTime.replace(/-/g, '/'))
          if (date < date1) {
            wx.showToast({
              title: '活动暂未开始',
              icon: 'none'
            })
            return;
          }
          if (date > date2) {
            wx.showToast({
              title: '活动已结束',
              icon: 'none'
            })
            return;
          }
        wx.navigateTo({
          url: '/pages/home/couponDetail/index2?stockId=' + item.stock
        });
        setTimeout(function () {
          wx.hideLoading()
        }, 1000)
      },

    getMember() {
        http.get('/api/user/getMemberInfo').then(res => {
            if (res.code == 200) {
                this.setData({
                    member: res.data
                })
            }
        })
        // http.get('/api/index/selectActivity', {type: 3}).then(res => {
        //     if (res.code == 200) {
        //         this.setData({
        //         activity: res.result
        //         })
        //     }
        // })
    },
  }
})
